#pragma once
#include "Figure.h"
#include "Position.h"
#include "Terreno.h"
#include "ConstructorTerreno.h"
#include <vector>
#include "StageParser.h"

class GameModel {
private:
	vector <Figure*> figures;
	Terreno* ground;
	b2World* world;
	
	unsigned int width;
	const float* hights;
	
	// PIXEL=LOGIC_UNIT*SCALE
	float scaleX;
	float scaleY;

	unsigned int logicWaterLevel;
		
	unsigned int height;

	float32 timeStep;
	int32 velocityIterations;
	int32 positionIterations;

	void GameModel::initFigure(Figure* figure);
	
	Position* GameModel::transformCoordBox2DToSDL(Position* position);
	
	bool GameModel::isPoligon(Figure* figure);
	bool GameModel::isCircle(Figure* figure);
	void GameModel::initPolygon(Figure* figure);
	void GameModel::initRectangle(Figure* figure);
	void GameModel::initCircle(Figure* figure);
	
	void GameModel::updateFiguresPosition();
	void GameModel::updatePosition(Figure* figure);
	void GameModel::updateCirclePositionShape(b2CircleShape* circle, Figure* figure);
	void GameModel::updatePolygonPositionShape(b2PolygonShape* polygon, Figure* figure);

	vector <Figure*> GameModel::cloneFigures(vector <Figure*> figuresParser);
	
public:
	GameModel();	

	Terreno* GameModel::getGround() { return this->ground; }

	vector <Figure*> GameModel::getFigures();
	void GameModel::setFigures(vector <Figure*> figures);

	void GameModel::setInitialPositionRectangle(Figure* figure);

	void setLogicWaterLevel(unsigned int logicWaterLevel);

	void GameModel::initGround();
	void GameModel::setParametersToInitGround(const float* hights, unsigned int width, unsigned int height);

	void GameModel::initFigures();	
	
	void GameModel::step();

	float getScaleX() { return this->scaleX; }
	float getScaleY() { return this->scaleY; };

	~GameModel();
};

